#include "calibration.h"
#include "ui_calibration.h"

extern Widget *w;

calibration::calibration(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::calibration)
{
    ui->setupUi(this);
}

calibration::~calibration()
{
    delete ui;
}
void calibration::set_wh(int w, int h)
{
    ui->horizontalLayoutWidget->setGeometry(0, 0, w, h);
}
void calibration::CtrDebug(QString color, QString text)
{
    QTime time = QTime::currentTime();
    QString EndStr;
    EndStr.append("<font size=\" 4\";>[");
    EndStr.append(time.toString());
    EndStr.append("] : </font><font size=\" 4\"; color =\"");
    EndStr.append(color);
    EndStr.append("\">");
    EndStr.append(text);
    EndStr.append("</font>");

    ui->Debug_Ctrl->append(EndStr);
    ui->Debug_Ctrl->moveCursor(QTextCursor::End);
}
void calibration::CtrDebug(QString color1, QString text1, QString color2, QString text2)
{
    QTime time = QTime::currentTime();
    QString EndStr;
    EndStr.append("<font size=\" 4\";>[");
    EndStr.append(time.toString());
    EndStr.append("] : </font><font size=\" 4\"; color =\"");
    EndStr.append(color1);
    EndStr.append("\">");
    EndStr.append(text1);
    EndStr.append("</font>");
    EndStr.append(" <font size=\" 4\"; color =\"");
    EndStr.append(color2);
    EndStr.append("\">");
    EndStr.append(text2);
    EndStr.append("</font>");

    ui->Debug_Ctrl->append(EndStr);
    ui->Debug_Ctrl->moveCursor(QTextCursor::End);

}

void calibration::SetIn_Angle0Value(uint16_t num)
{
    ui->In_Angle0Value->setValue(num);
}

void calibration::SetIn_ppnum(uint16_t num)
{
    ui->In_ppnum->setValue(num);
}
void calibration::SetIn_R(float num)
{
    ui->In_R->setValue(num);
}
void calibration::SetIn_L(float num)
{
    ui->In_L->setValue(num);
}
void calibration::on_Bt_StartCalib_clicked()
{
    QMessageBox::warning(w, "警告", "你的电机会转动噢，请注意安全!");
    qDebug()<<"确实点击了确定才会发送校准命令";
    uint8_t PolePairs = this->ui->In_ppnum->value();    //将设置的极对数发送出去
    if (uartComm.tx_data(M_Calibration,&PolePairs,1) == Comm_OK) {
        this->CtrDebug("#7E57C2", "成功发送校准命令!!!");
    } else {
        this->CtrDebug("#F48FB1", "发送有误，请检查你的设置❌❌❌");
    }
}
